package org.agile.grenoble.nokiatest;

import java.util.*;

public class QuestionnaireRepondu
{
	protected Questionnaire questionnaire = null;
	Set<IReponse> reponses = null;
	int scoreTotal = 0;
	
	public QuestionnaireRepondu(Questionnaire questionnaire)
	{
		this.questionnaire = questionnaire;
		this.reponses = new LinkedHashSet<IReponse>();
	}
	
	public void addReponse(int numQuestion, String reponse)
	{
		reponses.add(new Reponse(numQuestion, reponse));
	}
	
	public void addReponseAdditionnelle(int numQuestion, String questionAdditionnelle, String reponseAdditionnelle)
	{
		reponses.add(new ReponseAdditionnelle(numQuestion, questionAdditionnelle, reponseAdditionnelle));
	}
	
	public int getScoreTotal()
	{
		return scoreTotal;
	}
	
	public void setScoreTotal(int scoreTotal)
	{
		this.scoreTotal= scoreTotal;
	}
	
	public void calculScoreTotal()
	{
            IReponse currentReponse = null;
            IReponseScore currentReponseScore=null;
            for (Iterator<IReponse> it = reponses.iterator(); it.hasNext();) {
                currentReponse = it.next();
                currentReponseScore = questionnaire.findReponseScore(currentReponse.getNumQuestion(), currentReponse.getReponse());
                assert currentReponseScore != null : "Il n'existe pas de reponse " + currentReponse.getReponse() + " pour la question " + Integer.valueOf(currentReponse.getNumQuestion());
                scoreTotal += currentReponseScore.getScore();
            }
	}
}